package com.xiaoyu.string;

import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion;

/**
 * Created by xiaoyu on 16/3/30.
 *
 *
 *
 public com.xiaoyu.string.ClassInitialize2();
 descriptor: ()V
 flags: ACC_PUBLIC
 Code:
 stack=4, locals=1, args_size=1
 0: aload_0
 1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 4: aload_0
 5: bipush        100
 7: putfield      #2                  // Field myId2:I
 10: aload_0
 11: invokevirtual #3                  // Method print:()V
 14: aload_0
 15: ldc           #4                  // String text1-0
 17: putfield      #5                  // Field myText1:Ljava/lang/String;
 20: aload_0
 21: ldc           #6                  // String text1-1
 23: putfield      #5                  // Field myText1:Ljava/lang/String;
 26: aload_0
 27: aconst_null
 28: putfield      #7                  // Field myText2:Ljava/lang/String;
 31: aload_0
 32: invokevirtual #3                  // Method print:()V
 35: aload_0
 36: bipush        100
 38: putfield      #8                  // Field myId1:I
 41: aload_0
 42: ldc           #4                  // String text1-0
 44: putfield      #5                  // Field myText1:Ljava/lang/String;
 47: aload_0
 48: new           #9                  // class java/lang/String
 51: dup
 52: ldc           #10                 // String text2
 54: invokespecial #11                 // Method java/lang/String."<init>":(Ljava/lang/String;)V
 57: putfield      #7                  // Field myText2:Ljava/lang/String;
 60: return

 1、可以看出，非静态代码块的执行最终也是被放进构造函数中完；

 2、代码块与成员属性的初始化顺序也是按其在代码中出现的先后顺序，如(2)(3)所示；

 3、所以在执行(1)print时，实际上myText1还没有被任何的初始化，包括成员属性的赋值，所以这时输出text:null；

 4、实际上 myText1是在(2)才有值，但紧接着还会被(3)给替换，所 在执行(4)时输出text:text1-1；


 */
public class ClassInitialize2 {

    //声明类的成员属性
    private int myId1;
    private int myId2= 100;
    //非静态代码块
    {
        print();  //(1)
        myText1="text1-0";   //(2)
    }

    private String myText1 = "text1-1";  //(3)
    private String myText2 = null;
    //显示构造函数


    public ClassInitialize2() {
        print();   //(4)
        myId1=100;
        myText1 = "text1-0";
        myText2 = new String("text2");
    }

    public void print(){
        System.out.println("text:"+myText1);
    }

    public static void main(String[] args) {
//        ClassInitialize2 c  = new ClassInitialize2();
//        StaticFieldInitialize s = new StaticFieldInitialize();
//        System.out.println(StaticFieldInitialize.class);
    }

}
